package com.codeduck.kafka.event.push;

import com.codeduck.kafka.event.message.MessageInfo;
import com.codeduck.kafka.event.message.MessageEvent;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Scope;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

@EnableAsync
@Component
@Scope("prototype")
public class EventPublisher implements IPublisher {

    @Resource
    private ApplicationContext applicationContext;

    @Override
    public void publishEvent(Object var) {
        MessageEvent messageEvent = new MessageEvent(this, (MessageInfo) var);
        this.applicationContext.publishEvent(messageEvent);
    }
}
